#!/usr/bin/perl


# This file is part of qorg11 blog

# qorg11 blog is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# qorg11 blog is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with qorg11 blog.  If not, see <https://www.gnu.org/licenses/>.


use SQLite::DB;
use Data::Dumper;
use CGI;

my $q = CGI->new;

my $db = SQLite::DB->new('articles.sqlite');

$db->connect;
# Get number of entires
my $EntriesMin = $db->select_one_row("select * from blog")->{ID};
my $EntriesMax = $db->select_one_row("select * from blog order by id desc")->{ID};

print "Content-type: text/html\n\n";
print "<!DOCTYPE html>";
print "<html lang=es>";
print "<head>";
print "<meta charset=utf-8>";
print "<title>Blog qorg</title>";
print "<link rel='stylesheet' href='https://qorg.duckdns.org/css/styles.css'>";
print "<style>  p{max-width: 800px;} body{background-color:black;} h3,b,i,h1,p{color:white;} .border{border-style:solid; border-color:red;}</style>";
print "</head>";
print " <div class='header'>

    <a href='/'>
    <img alt='lain' src='/img/favicon.gif' width='100' height='100'>
    </a>
    <div class='menu'>

    <a href='/info.html'>Información</a>
    <a href='https://vid.qorg.duckdns.org'>vídeos</a>
    <a href='https://underflow.ga'>página de dmg</a>
    </div>
    </div>
    ";


for(my $x = $EntriesMax; $x >= $EntriesMin; $x-- ) {
    print "<div class='border'>";
    my $entries = $db->select_one_row("select * from blog where id == $x");
    print "<h3 id='$entries->{ID}' >$entries->{TITLE}</h3>";
    print "<p>$entries->{CONTENT}</p>";
    print "<p>publicado $entries->{DATE}</p>";
    print "</div>";


}
print "</body>";
print "</html>";
